package com.pocketcloud.controller;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import org.slim3.controller.Navigation;
import org.slim3.util.ResponseLocator;

import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import com.pocketcloud.base.PcControllerBase;

public class PdfController extends PcControllerBase {

	@Override
	public Navigation run() throws Exception {
		HttpServletResponse res = ResponseLocator.get();
		res.setContentType("application/pdf");

		Font font = new Font(BaseFont.createFont("HeiseiKakuGo-W5",
				"UniJIS-UCS2-H", BaseFont.NOT_EMBEDDED), 15, Font.NORMAL);

		ByteArrayOutputStream baos = new ByteArrayOutputStream();

		Document document = new Document();
		PdfWriter.getInstance(document, baos);
		document.open();
		document.add(new Paragraph("こんにちは！", font));
		document.addTitle("hello world");
		document.close();

		OutputStream os = res.getOutputStream();
		os.write(baos.toByteArray());
		return null;
		// return forward("index.jsp");
	}
}
